package bma.common.thrift.xdom;

import java.util.ArrayList;
import java.util.List;

import bma.common.langutil.core.StringUtil;

public class TDynamicStruct {

	private String name;
	private boolean callArgs;
	private boolean callReturn;
	private List<TDynamicField> fields;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isCallArgs() {
		return callArgs;
	}

	public void setCallArgs(boolean callArgs) {
		this.callArgs = callArgs;
	}

	public boolean isCallReturn() {
		return callReturn;
	}

	public void setCallReturn(boolean callReturn) {
		this.callReturn = callReturn;
	}

	public List<TDynamicField> getFields() {
		return fields;
	}

	public void setFields(List<TDynamicField> fields) {
		this.fields = fields;
	}
	
	public void addField(TDynamicField field) {
		if(this.fields==null)this.fields = new ArrayList<TDynamicField>();
		this.fields.add(field);
	}

	public TDynamicField getField(int key) {
		if (this.fields != null) {
			for (TDynamicField f : this.fields) {
				if (f.getKey() == key)
					return f;
			}
		}
		return null;
	}

	public TDynamicField getField(String name) {
		if (this.fields != null) {
			for (TDynamicField f : this.fields) {
				if (StringUtil.equals(f.getName(), name))
					return f;
			}
		}
		return null;
	}
}
